﻿function getParams() {

    var params = {};

    var cardNumber = $("input[name='cardNumber']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
        params.cardNumber = cardNumber;
    }

    var startTime = $("input[name='startTime']").val(); 
    if (!FlashPay.Util.isNullOrEmptySpance(startTime)) {
        params.startTime = startTime;
    }

    var endTime = $("input[name='endTime']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(endTime)) {
        params.endTime = endTime;
    }

    return params;
}

function doSearch() {

    var params = {};

    var cardNumber = $("input[name='cardNumber']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
        params.cardNumber = cardNumber;
    }

    var startTime = $("input[name='startTime']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(startTime)) {
        params.startTime = startTime;
    }

    var endTime = $("input[name='endTime']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(endTime)) {
        params.endTime = endTime;
    }


    //FlashPay.Util.Ajax({
    //    type: "POST",
    //    url: "/Report/BankDetail",
    //    data: params,
    //    success: function (res) {
    //        if (res.success) {
                
    //        } else {
    //            FlashPay.UI.Tip_short_warning(res.errorMessage);
    //        }
    //    },
    //    error: function (e) {
    //        cover.Remove();

    //        FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
    //    }
    //});

    init();
}

function init() {

    var frozenColumns = [[
        { field: 'bankName', title: '银行名称', width: 100, align: 'left' },
        { field: 'cardName', title: '用户名', width: 150, align: 'left' },
    ]];

    var columns = [[
        {
            field: 'recordType', title: '类型', width: 100, align: 'left',
            formatter: function (val, row) {

                switch (val) {
                    case 1:
                        return "<span class=\"green bold\">存款</span>";
                        break;
                    case 2:
                        return "<span class=\"red bold\">付款</span>";
                        break;
                    default:
                        return "";
                        break;
                }
            }
        },
        {
            field: 'balance', title: '存、付款后余额', width: 100, align: 'right',
            formatter: function (val, row) {
                return "<span class=\"bold\">{0}</span>".format(FlashPay.Util.FormatNumber(val, 2));
            }
        },
        {
            field: 'amount', title: '金额', width: 100, align: 'right',
            formatter: function (val, row) {
                return "<span class=\"bold\">{0}</span>".format(FlashPay.Util.FormatNumber(val, 2));
            }
        },
        { field: 'clientBankName', title: '交易类型', width: 100, align: 'left' },
        { field: 'clientAccountName', title: '客户姓名', width: 100, align: 'left' },
        { field: 'clientCardNumber', title: '客户卡号', width: 200, align: 'left' },
        { field: 'operatingDateText', title: '操作时间', width: 150, align: 'left' },
        { field: 'createDBDateText', title: '创建时间', width: 150, align: 'left' }
    ]];


    $("#transfercard").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        url: '/Report/BankDetail',
        queryParams: getParams(),
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        idField: 'bcId',
        onLoadSuccess: function (data) {
            if (!data.success) {
                FlashPay.UI.Tip_warning(data.errorMessage);
            }
            pageSize = $('#transfercard').datagrid('options').pageSize;
        },
        //fitColumns: true,
        emptyMsg: '<span>无记录</span>',
        showFooter: true,
        frozenColumns: frozenColumns,
        columns: columns
    });
}

function inits() {

    var frozenColumns = [[
        { field: 'bankName', title: '银行名称', width: 100, align: 'left' },
        { field: 'cardName', title: '用户名', width: 150, align: 'left' },
    ]];

    var columns = [[
        {
            field: 'recordType', title: '类型', width: 100, align: 'left',
            formatter: function (val, row) {

                switch (val) {
                    case 1:
                        return "<span class=\"green bold\">存款</span>";
                        break;
                    case 2:
                        return "<span class=\"red bold\">付款</span>";
                        break;
                    default:
                        return "";
                        break;
                }
            }
        },
        {
            field: 'balance', title: '存、付款后余额', width: 100, align: 'right',
            formatter: function (val, row) {
                return "<span class=\"bold\">{0}</span>".format(FlashPay.Util.FormatNumber(val, 2));
            }
        },
        {
            field: 'amount', title: '金额', width: 100, align: 'right',
            formatter: function (val, row) {
                return "<span class=\"bold\">{0}</span>".format(FlashPay.Util.FormatNumber(val, 2));
            }
        },
        { field: 'clientBankName', title: '客户银行名称', width: 100, align: 'left' },
        { field: 'clientAccountName', title: '客户姓名', width: 100, align: 'left' },
        { field: 'clientCardNumber', title: '客户卡号', width: 200, align: 'left' },
        { field: 'operatingDateText', title: '操作时间', width: 150, align: 'left' },
        { field: 'createDBDateText', title: '创建时间', width: 150, align: 'left' }
    ]];


    $("#transfercard").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        queryParams: getParams(),
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        idField: 'bcId',
        onLoadSuccess: function (data) {
        },
        //fitColumns: true,
        emptyMsg: '<span>无记录</span>',
        showFooter: true,
        frozenColumns: frozenColumns,
        columns: columns
    });
}

$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};